package ATM.gui;

import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JTextField;
import javax.swing.JButton;

import ATM.data.Accounts;
import ATM.data.Customers;

public class ViewCustomer extends JPanel {
	Screen screen;
	private JLabel tfldcustomerid;
	private JLabel tfldpassword;
	private JTextField tfldFirstName;
	private JTextField tfldLastName;
	private JTextField tfldCpr;
	private JTextField tfldAddress;
	private JTextField tfldZipcode;
	private JTextField tfldCity;
	private JTextField tfldCountry;
	private JTextField tfldPhoneNumber;
	private JTextField tlfdMail;
	private JTextField tlfdsearch;

	public ViewCustomer(Screen screen) {
		this.screen = screen;
		setLayout(null);

		JLabel lblCustomersId = new JLabel("Customers ID:");
		lblCustomersId.setBounds(199, 98, 101, 14);
		add(lblCustomersId);

		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(199, 123, 101, 14);
		add(lblPassword);

		JLabel lblFirstName = new JLabel("First name :");
		lblFirstName.setBounds(199, 159, 101, 14);
		add(lblFirstName);

		JLabel lblLastName = new JLabel("Last name");
		lblLastName.setBounds(199, 184, 101, 14);
		add(lblLastName);

		JLabel lblCpr = new JLabel("CPR");
		lblCpr.setBounds(199, 209, 101, 14);
		add(lblCpr);

		JLabel lblAddress = new JLabel("Address");
		lblAddress.setBounds(199, 235, 101, 14);
		add(lblAddress);

		JLabel lblZipcode = new JLabel("Zipcode ");
		lblZipcode.setBounds(199, 260, 101, 14);
		add(lblZipcode);

		JLabel lblCity = new JLabel("City");
		lblCity.setBounds(199, 285, 101, 14);
		add(lblCity);

		JLabel lblCountry = new JLabel("Country");
		lblCountry.setBounds(199, 310, 101, 14);
		add(lblCountry);

		JLabel lblPhoneNumber = new JLabel("Phone number");
		lblPhoneNumber.setBounds(199, 335, 101, 14);
		add(lblPhoneNumber);

		JLabel lblEmail = new JLabel("E-mail:");
		lblEmail.setBounds(199, 360, 101, 14);
		add(lblEmail);

		tfldcustomerid = new JLabel();
		tfldcustomerid.setBounds(310, 98, 152, 20);
		// tfldcustomerid.setEnabled(false);
		add(tfldcustomerid);
		// tfldcustomerid.setColumns(10);

		tfldpassword =  new JLabel();
		tfldpassword.setBounds(310, 123, 152, 20);
		add(tfldpassword);

		tfldFirstName = new JTextField();
		tfldFirstName.setBounds(310, 159, 152, 20);
		add(tfldFirstName);
		tfldFirstName.setColumns(10);

		tfldLastName = new JTextField();
		tfldLastName.setBounds(310, 184, 152, 20);
		add(tfldLastName);
		tfldLastName.setColumns(10);

		tfldCpr = new JTextField();
		tfldCpr.setBounds(310, 209, 152, 20);
		add(tfldCpr);
		tfldCpr.setEditable(false);
		
		tfldCpr.setColumns(10);

		tfldAddress = new JTextField();
		tfldAddress.setBounds(310, 232, 152, 20);
		add(tfldAddress);
		tfldAddress.setColumns(10);

		tfldZipcode = new JTextField();
		tfldZipcode.setBounds(310, 257, 152, 20);
		add(tfldZipcode);
		tfldZipcode.setColumns(10);

		tfldCity = new JTextField();
		tfldCity.setBounds(310, 282, 152, 20);
		add(tfldCity);
		tfldCity.setColumns(10);

		tfldCountry = new JTextField();
		tfldCountry.setBounds(310, 307, 152, 20);
		add(tfldCountry);
		tfldCountry.setColumns(10);

		tfldPhoneNumber = new JTextField();
		tfldPhoneNumber.setBounds(310, 332, 152, 20);
		add(tfldPhoneNumber);
		tfldPhoneNumber.setColumns(10);

		tlfdMail = new JTextField();
		tlfdMail.setBounds(310, 357, 152, 20);
		add(tlfdMail);
		tlfdMail.setColumns(10);

		JButton btnPrevious = new JButton("Previous");
		btnPrevious.setBounds(10, 55, 128, 28);
		add(btnPrevious);
		btnPrevious.setActionCommand("PreviousVC");
		btnPrevious.addActionListener(screen.getAdminaL());

		JButton btnNext = new JButton("Next");
		btnNext.setBounds(502, 55, 128, 28);
		add(btnNext);
		btnNext.setActionCommand("NextVC");
		btnNext.addActionListener(screen.getAdminaL());

		JLabel lblSearchByCustomers = new JLabel("Search by Customers ID:");
		lblSearchByCustomers.setBounds(148, 430, 152, 14);
		add(lblSearchByCustomers);

		tlfdsearch = new JTextField();
		tlfdsearch.setBounds(310, 427, 86, 20);
		add(tlfdsearch);

		JButton btnSearch = new JButton("Search");
		btnSearch.setBounds(406, 426, 89, 23);
		add(btnSearch);
		btnSearch.setActionCommand("SearchByCustomerID");
		btnSearch.addActionListener(screen.getAdminaL());

		JButton btnExit = new JButton("Exit");
		btnExit.setBounds(502, 356, 128, 28);
		add(btnExit);
		btnExit.setActionCommand("Exit");
		btnExit.addActionListener(screen.getaL());

		JButton btnAddAccount = new JButton("Add account");
		btnAddAccount.setBounds(502, 246, 128, 28);
		add(btnAddAccount);
		btnAddAccount.setActionCommand("AddAccount");
		btnAddAccount.addActionListener(screen.getAdminaL());

		JButton btnDeleteButton = new JButton("Delete account");
		btnDeleteButton.setBounds(502, 281, 128, 28);
		add(btnDeleteButton);
		btnDeleteButton.setActionCommand("DeleteCustomerAccount");
		btnDeleteButton.addActionListener(screen.getAdminaL());
		
		JButton btnEdit = new JButton("Edit");
		btnEdit.setBounds(502, 316, 128, 28);
		add(btnEdit);
		btnEdit.setActionCommand("Edit");
		btnEdit.addActionListener(screen.getAdminaL());

		JLabel image = (new JLabel(screen.getVariables().getImage1()));
		image.setBounds(0, 0, 640, 480);
		add(image);
	}

	public void setTextField(String customerid, String password,
			String firstname, String lastname, String cpr, String address,
			String zipcode, String city, String country, String phone,
			String mail) {
		tfldcustomerid.setText(customerid);
		tfldpassword.setText(password);
		tfldFirstName.setText(firstname);
		tfldLastName.setText(lastname);
		tfldCpr.setText(cpr);
		tfldAddress.setText(address);
		tfldZipcode.setText(zipcode);
		tfldCity.setText(city);
		tfldCountry.setText(country);
		tfldPhoneNumber.setText(phone);
		tlfdMail.setText(mail);
	}

	public ArrayList<Customers> EditCustomer() {
		ArrayList<Customers> customers = new ArrayList<Customers>();
		customers.add(new Customers( Integer.parseInt(tfldcustomerid.getText()),  Integer.parseInt(tfldpassword
				.getText()), tfldFirstName.getText(), tfldLastName.getText(),
				tfldCpr.getText(), tfldAddress.getText(), Integer.parseInt(
				tfldZipcode.getText()), tfldCity.getText(), tfldCountry
						.getText(),  Integer.parseInt(tfldPhoneNumber.getText()), tlfdMail
						.getText()));
		return customers;

	}

	public JTextField getTlfdsearch() {
		return tlfdsearch;
	}

	public JLabel getTfldcustomerid() {
		return tfldcustomerid;
	}
}
